<template>
  <div class="repayment">

<div>  
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="社会信用代码"  style="width: 300px">
    <el-input type="text" v-model="ruleForm.code" autocomplete="off"  :disabled="true"></el-input>
  </el-form-item>
  <el-form-item label="客户名称"  style="width: 300px" >
    <el-input type="text" v-model="ruleForm.enterprisename" autocomplete="off" :disabled="true"></el-input>
  </el-form-item>
  <el-form-item label="期限"  style="width: 300px">
    <el-input v-model.number="ruleForm.term" :disabled="true"></el-input>
  </el-form-item>
   <el-form-item label="借款金额"  style="width: 300px">
    <el-input v-model.number="ruleForm.borrowed" :disabled="true"></el-input>
  </el-form-item>


<el-form-item label="还款日期"  style="width: 300px">
    <el-input type="date" v-model="ruleForm.applicationtime" autocomplete="off"  ></el-input>
  </el-form-item>

<el-form-item label="还款期次" prop="pass" style="width: 300px">
    <el-input type="text" v-model="ruleForm.terms" autocomplete="off"  ></el-input>
  </el-form-item>

<el-form-item label="应还本金"  style="width: 300px; position: relative;
 left: 350px;top:-370px"     prop="shouldprincipal">
    <el-input type="text" v-model="ruleForm.shouldprincipal" autocomplete="off"  ></el-input>
  </el-form-item>


<el-form-item label="应还利息"  style="width: 300px; position: relative;
 left: 350px;top:-370px"     prop="overdue">
    <el-input type="text" v-model="ruleForm.overdue" autocomplete="off"  ></el-input>
  </el-form-item>

<el-form-item label="应还罚息"  style="width: 300px; position: relative;
 left: 350px;top:-370px"     prop="repaymentstatuss">
    <el-input type="text" v-model="ruleForm.repaymentstatuss" autocomplete="off"  ></el-input>
  </el-form-item>

  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
</div>
  </div>
</template>

<script>
export default {
  data () {
    var shouldprincipal = (rule, value, callback) => {
        console.log("this.ruleForm.shouldprincipal--"+this.ruleForm.shouldprincipal)
       
        if (!value) {
          return callback(new Error('本金不能为空'));
        }
        setTimeout(() => {
          if (value < 100 ) {
           callback(new Error('本金不能低于100元'));
          }else if( value >this.ruleForm.borrowed){
             callback(new Error('本金不能高于欠款总额元'));
          }else{
            callback();
          }
          
        }, 1000);
      };
     var repaymentstatuss = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('罚息不能为空'));
        }
        setTimeout(() => {
          if (value < 10) {
           callback(new Error('罚息不能低于10元'));
          } else {
            callback();
              
            } 
          
        }, 1000);
      };
    var checkAge = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('利息不能为空'));
        }
        setTimeout(() => {
          if (value < 10) {
           callback(new Error('利息不能低于10元'));
          } else {
            callback();
              
            } 
          
        }, 1000);
      };
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
    return {
      
       ruleForm: {
          pass: '',
          checkPass: '',
          age: '',
          overdue:'',
          repaymentstatus:'',
          shouldprincipal:'',
          repaymentdate:'',
          repaymentstatuss:''
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          age: [
            { validator: checkAge, trigger: 'blur' }
          ],
          overdue: [
            { validator: checkAge, trigger: 'blur' }
          ],
          repaymentstatuss: [
            { validator: repaymentstatuss, trigger: 'blur' }
          ],
           shouldprincipal: [
            { validator: shouldprincipal, trigger: 'blur' }
          ],
        },
      
      pageSize:7,
     
      totalRecord:this.totalRecord,
       currentPage4: 1,
     tableData: [],
      formInline: {
          user: '',
          region: ''
        }
    }
  },
  created(){
      this.init()
      
      var reid=this.$route.query.reid
      console.log("reid是"+reid)
  },

  methods:{
    //当前时间
    getCurrentTime() {
      //获取当前时间并打印
      var _this = this;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      _this.rtime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
      console.log(_this.rtime);
      this.applicationtime = _this.rtime;
    },
     onSubmit() {
        console.log('submit!');
        this.$axios.get("http://localhost:8082/loanmanage/selcetByname", 
        {params: {
            enterprisename:this.formInline.enterprisename,
            code:this.formInline.code
        }}).then(resp=>{
    
          console.log(resp)
        })
      },
     handleSizeChange(val) {
       this.pageSize=val
        console.log(`每页 ${val} 条`);
         this.init();
      },
      handleCurrentChange(val) {
          this.currentPage4=val
        console.log(`当前页: ${val}`);
        this.init();
      },
    handleClick(row) {
        console.log(row);
      },
    init(){
     
       console.log("row");
        var reid=this.$route.query.reid
      this.$axios
        .get("http://localhost:8082/RepaymentRegistered/RepaymentReid", {
          params: {
            
            reid:reid
          }
        })
        .then(resp => {
         this.ruleForm=resp.data
         console.log(resp);
        });
    },
    submitForm(formName) {
      
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
 var reid=this.$route.query.reid
//   console.log("formName------"+this.ruleForm.repaymentdate)
          this.$axios
        .get("http://localhost:8082/RepaymentRegistered/insert", {
          params: {
            repaymentdate:this.ruleForm.repaymentdate,
            overdue:this.ruleForm.overdue,
            repaymentstatus:this.ruleForm.repaymentstatuss,
            shouldprincipal:this.ruleForm.shouldprincipal,
           reid:reid,
           shouldtotal:this.ruleForm.borrowed,
          
          }
        })
        .then(resp => {
        
        });

 this.$router.push("/repayment");





          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    
  }
}
</script>

<style >
.block{
 position: relative;
 left: 350px;
 top: 200px;


}


</style>